import java.net.ConnectException;
import java.util.InputMismatchException;
import java.util.Scanner;


public class Main {


	public static void main(String[] args) {
		
		String host = null;
		int port = 0;
	
		Scanner scan=new Scanner(System.in);
		while(true){
			System.out.println("*********************************************************");
			System.out.println("Possible client commands:");
			System.out.println("Press 1 for getting the average temperature.");
			System.out.println("Press 2 for starting the admin shifting procedure.");
			System.out.println("...");
			try{
			int command=scan.nextInt();
			scan.nextLine();
			System.out.println("*********************************************************");
			switch (command) {
			case 1:
				System.out.println("Enter the ip:port of the admin node you want to connect to.");
				String[] ipAndPort=scan.nextLine().split(":");
				host = ipAndPort[0];
				port = Integer.parseInt(ipAndPort[1]);
			    double avgResponse = Client.getAvg(host, port);
				if(avgResponse!=-1){
					System.out.println("The average temperature is: " + avgResponse);
				}
				break;

			case 2:
				System.out.println("Enter the ip:port of the regular node you want to connect to:");
				String [] ipAndPort2=scan.nextLine().split(":");
				host = ipAndPort2[0];
				port = Integer.parseInt(ipAndPort2[1]);
				String newAdminResponse = Client.shiftAdmin(host, port);
				System.out.println(newAdminResponse);
				break;
			}
			
			}catch (InputMismatchException e) {
				System.out.println("Incorrect command. Try again...");
			}
		}
	}

}
